package com.zhang.zhangapp.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.lzy.imagepicker.bean.ImageItem;
import com.zhang.zhangapp.R;
import com.zhang.zhangapp.view.adapter.FragmentAdapter;
import com.zhang.zhangapp.view.shop.ImageFragment;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 罗肖 on 2018/4/20.
 */

@ContentView(R.layout.activity_preview_image)
public class ImagePreviewActivity extends BaseAppCompatActivityActivity {
    @ViewInject(R.id.viewpager)
    ViewPager viewPager;
    @ViewInject(R.id.action_bar_title)
    TextView titleText;
    ArrayList<ImageItem> imageItemArrayList;
    List<Fragment> fragmentList = new ArrayList<>();
    FragmentAdapter adapter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        imageItemArrayList = getIntent().getParcelableArrayListExtra("images");
        initView();
    }

    @Event(type = View.OnClickListener.class,value = R.id.action_bar_left_image)
    private void back(View view){
        this.finish();
    }

    private void initView() {
        if (imageItemArrayList != null) {
            for (ImageItem imageItem : imageItemArrayList) {
                Bundle bundle = new Bundle();
                bundle.putParcelable("image",imageItem);
                ImageFragment fragment = new ImageFragment();
                fragment.setArguments(bundle);
                fragmentList.add(fragment);
            }
            adapter = new FragmentAdapter(getSupportFragmentManager(),fragmentList);
            viewPager.setAdapter(adapter);
        }
    }
}
